<template>
	<view class="positopbgc mainpadding">
		<view class="titletext bold hei_text" style="margin-top: 200rpx;">欢迎登陆</view>
		<view class="pdl" style="margin-top: 100rpx;">
			<input type="text" class=" hei_text main_size bold" placeholder="请输入用户名" style="width: 100%;" v-model="username">
		</view>
		<view class="pdl margin_top4">
			<input type="password" class=" hei_text main_size bold" placeholder="请输入密码" style="width: 100%;" v-model="password">
		</view>
		<view class="flexbetween xiaohei margin_top4">
			<view @click="show=true">忘记密码</view>
			<view @click="jumpurl('/pages/login/signIn')">立即注册</view>
		</view>
		<view class="mainpadding_top flexleft margin_top6"  @click="checkaudio">
			<view class="nocheckaudio" v-show="!type"></view>
			<view class="checkaudio" v-show="type"></view>
			<view class="xiaohui margin_left1">
				阅读并同意
				<text class="xiaolan" @click.stop="jumpurl('/pages/login/system?type=1')">《用户协议》</text>
				和
				<text class="xiaolan" @click.stop="jumpurl('/pages/login/system?type=2')">《隐私政策》</text>
			</view>
		</view>
		<view class="submitbtn margin_top6" @click="login">登录</view>
		<u-modal :show="show" title="忘记密码" @confirm="confirm" confirmText="点击复制">
			<view class="mainpadding margin_top4 flexcolumn">
				<view class="xiaolan">18574139993</view>
				<view class="xiaohui margin_top">请添加管理员微信更改密码</view>
			</view>
		</u-modal>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				show: false,
				type:false,
				username:"",
				password:"",
			}
		},
		methods: {
			checkaudio(){
				this.type = !this.type
			},
			wxlogin() {
				let _this = this
				uni.login({
					success(res) {
						if (res.code) {
							httpRequest.request('/api/user/login_hawk', 'GET', {
								code:res.code
							}).then(resp => {
								uni.setStorageSync('openid',resp.data.openid);
							}).catch(err=>{
							})
						}
					}
				})
			},
			login(){
				if(this.username==""){
					httpRequest.toast("请输入用户名");
					return false;
				}
				if(this.password==""){
					httpRequest.toast("请输入密码")
					return false
				} 
				if(!this.type){
					httpRequest.toast("请认真阅读并勾选用户协议");
					return false;
				}
				httpRequest.request('/api/user/login','POST',{
					username:this.username, 
					password:this.password
				}).then(res => {
					if(res.code == 1){
						httpRequest.toast('登录成功');
						this.wxlogin()
						uni.setStorageSync('token',res.data.userinfo.token);
						uni.setStorageSync('user_id',res.data.userinfo.user_id);
						setTimeout(()=>{
							uni.navigateBack(1)
						},1000)
					}else{
						httpRequest.toast(res.msg);
					}
				})
			},
			confirm() {
				this.show = false
				uni.setClipboardData({
					data: "1837283092", //要被复制的内容
					success: () => {
						//复制成功的回调函数
						httpRequest.toast("复制成功")
					}
				});
			},
			jumpurl(url){
				uni.navigateTo({
					url
				})
			}
		}
	}
</script>

<style scoped>
	.pdl {
		padding-bottom: 40rpx;
	}
</style>